package com.yunhe.rentcars.pro.service.system.impl;

import com.yunhe.rentcars.commons.annoaction.Log;
import com.yunhe.rentcars.commons.dto.Pageable;
import com.yunhe.rentcars.pro.dao.system.DeptDao;
import com.yunhe.rentcars.pro.entity.system.Dept;
import com.yunhe.rentcars.pro.service.system.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptDao deptDao;
    @Override
    @Log(value = "添加新门店",type = 1)
    public void save(Dept dept) {
        deptDao.save(dept);

    }

    @Override
    @Log(value = "删除门店",type = 2)
    public void delete(Long id) {
        deptDao.delete(id);

    }

    @Override
    @Log(value = "修改门店",type = 3)
    public void update(Dept dept) {
        deptDao.update(dept);

    }

    @Override
    public Pageable<Dept> findPage(Integer offset, Integer limit) {
        Pageable<Dept> pageable = new Pageable<>();
        List<Dept> rows = new ArrayList<>();
        int count = deptDao.findCount();
        if(count > 0){
            rows = deptDao.findList(offset, limit);
        }
        pageable.setTotal(count);
        pageable.setRows(rows);
        return pageable;
    }

    @Override
    public Dept findOne(Long id) {
        return deptDao.findOne(id);
    }
}
